package com.epam.productxslt.command;

import java.util.concurrent.ConcurrentHashMap;

import com.epam.productxslt.controller.RequestContent;


public final class CommandManager {
	private static final String COMMAND_PARAMETER_NAME = "command";
	private static ConcurrentHashMap<CommandType, Command> commands = new ConcurrentHashMap<CommandType, Command>();
	static {
		commands.put(CommandType.CATEGORIES, new CategoriesCommand());
		commands.put(CommandType.SUBCATEGORIES, new SubcategoriesCommand());
		commands.put(CommandType.GOODS, new GoodsCommand());
		commands.put(CommandType.ADD, new AddGoodsCommand());
		commands.put(CommandType.SAVE, new SaveGoodsCommand());
	}
	public static Command getCommand(RequestContent requestContent){
		String commandName = requestContent.getRequestParameter(COMMAND_PARAMETER_NAME);
		CommandType commandType = CommandType.valueOf(commandName.toUpperCase());
		Command command = commands.get(commandType);
		return command;
	}
	public static Command getCommand(CommandType commandType){
		return commands.get(commandType);
	}
}
